#include<cnedvalue.h>
#include<cnedfunction.h>
#include<distrib.h>

static int currentLambdaIndex = 0;

//0.2 3 4 5 6 7 8
static cNEDValue mmpp(cComponent *context, cNEDValue argv[], int argc){
    double p = (double)argv[0];

    double randomNumber = uniform(0,1);
        if(randomNumber < p) { //change lambda
            currentLambdaIndex = rand() % (argc-1); //select new lambda randomly
            currentLambdaIndex++; // offset from modulo operation
        }

    double currentLambda = (double)argv[currentLambdaIndex];
    long x = (long)poisson(currentLambda);
        return x;
}

EXECUTE_ON_STARTUP(nedFunctions.getInstance()->add(new cNEDFunction(mmpp,"int mmpp(double p, ...)"));)
